<script setup lang="ts">
import type { BackHistoryList } from '@/types/my.ts';
import { formatTime } from '@/utils';

const props = defineProps<{
  backHistoryList: BackHistoryList[];
  modelValue: boolean;
}>();
const $emit = defineEmits(['update:modelValue']);
const imageShow = ref(false);
const imagesList = ref<string[]>([]);
const onImageClick = (props: any) => {
  imageShow.value = true;
  imagesList.value = [props];
};
const show = computed({
  get: () => props.modelValue,
  set: (value) => {
    $emit('update:modelValue', value);
  },
});
</script>

<template>
  <van-popup v-model:show="show" position="bottom" :style="{ maxHeight: '70%' }">
    <div class="after-pop-container">
      <div class="title">售后明细</div>
      <van-steps :active="backHistoryList.length - 1" direction="vertical">
        <van-step v-for="item in backHistoryList" :key="item.id">
          <div class="history_progress" v-if="item.historyType === 'BACK_APPLY'">
            <div class="history-title">
              <div class="history-text">买家申请售后</div>
              <span class="history-time">{{ formatTime(item.createTime) }}</span>
            </div>
            <div class="history-status"><span>售后类型：</span>退货退款</div>
            <div><span>申请原因：</span>{{ item.historyVal.applyReason }}</div>
          </div>

          <div class="history_progress" v-if="item.historyType === 'AGREE_BACK'">
            <div class="history-title">
              <div class="history-text">卖家同意售后</div>
              <span class="history-time">{{ formatTime(item.createTime) }}</span>
            </div>
          </div>
          <div class="history_progress" v-if="item.historyType === 'DELIVERED'">
            <div class="history-title">
              <div class="history-text">买家退回商品</div>
              <span class="history-time">{{ formatTime(item.createTime) }}</span>
            </div>
            <div class="text">
              <span class="text-title">物流单号:</span>{{ item.historyVal.trackingNumber }}
            </div>
          </div>
          <div class="history_progress" v-if="item.historyType === 'RECEIVED'">
            <div class="history-title">
              <div class="history-text">卖家确认收货</div>
              <span class="history-time">{{ formatTime(item.createTime) }}</span>
            </div>
          </div>
          <div class="history_progress" v-if="item.historyType === 'REFUND'">
            <div class="history-title">
              <div class="history-text">卖家退款</div>
              <span class="history-time">{{ formatTime(item.createTime) }}</span>
            </div>
            <div class="text">
              <div class="text-title">退款凭证</div>
              <van-image
                class="qualica"
                @click="onImageClick(backPayProof)"
                v-for="(backPayProof, index) in item.historyVal.backPayProof?.split(',')"
                :key="index"
                :src="backPayProof"
              />
            </div>
          </div>
          <div class="history_progress" v-if="item.historyType === 'CONFIRM_RECEIPT'">
            <div class="history-title">
              <div class="history-text">买家确认收款</div>
              <span class="history-time">{{ formatTime(item.createTime) }}</span>
            </div>
            <div class="text">售后完成</div>
          </div>
          <div class="history_progress" v-if="item.historyType === 'REFUSE_BACK'">
            <div class="history-title">
              <div class="history-text">卖家拒绝售后</div>
              <span class="history-time">{{ formatTime(item.createTime) }}</span>
            </div>
            <div class="text">
              <span class="text-title">拒绝原因:</span>{{ item.historyVal.remark }}
            </div>
          </div>
        </van-step>
      </van-steps>
    </div>
  </van-popup>
  <van-image-preview v-model:show="imageShow" :images="imagesList" />
</template>

<style scoped lang="scss">
.after-pop-container {
  width: 100%;
  padding: 0 16px;

  .title {
    width: 100%;
    height: 40px;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    color: #000000;
  }

  .history_progress {
    width: 100%;
    font-size: 12px;
    font-weight: 400;
    color: #787878;

    .van-image {
      width: 64px;
      height: 64px;
    }

    .text {
      margin: 8px 0;
    }

    .text-title {
      margin: 8px 0;
    }

    .history-title {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: space-between;

      .history-text {
        font-size: 13px;
        font-weight: 500;
        color: #222222;
      }

      .history-time {
        font-size: 13px;
        font-weight: 500;
      }
    }

    .history-status {
      margin: 8px 0;
    }
  }
}
</style>
